/*
this checks that all arguments are integers and are greater than one another in reverse order
*/

 LT:
  PUSH(FP);
  MOV(FP,SP);

  PUSH(R1); //save R1
  PUSH(R2); //save R2
  PUSH(R3); //save R2
  PUSH(R4); //save R2
  MOV(R1, FPARG(1)); //R1=n
  CMP(R1,IMM(2));
  JUMP_LT(ARG_N_ERROR);
  MOV(R0, FPARG(R1+1)); //intialize R0=last argument
  

 L_LT_LOOP:
  SUB(R1,1);	
  MOV(R2,FPARG(R1+1)); //move argument n to R2
  MOV(R4,INDD(R2,1));
  CMP(IND(R0),IMM(T_INTEGER)); //check argument type
  JUMP_EQ(LT_EQ_INT1);
  CMP(IND(R0),IMM(T_FRACTION)); //check argument type
  JUMP_NE(TYPE_ERROR);
  MUL(R4,INDD(R0,2));
LT_EQ_INT1:
  MOV(R3,INDD(R0,1));
  CMP(IND(R2),IMM(T_INTEGER));
  JUMP_EQ(LT_EQ_INT2);
  CMP(IND(R2),IMM(T_FRACTION)); //check argument type
  JUMP_NE(TYPE_ERROR);
  MUL(R3,INDD(R2,2));
LT_EQ_INT2:
  
  CMP(R4,R3); 
  JUMP_GE(L_LT_F);
  MOV(R0,R2);
  CMP(R1, IMM(1)); //check if n is 1
  JUMP_NE(L_LT_LOOP);

MOV(R0, IMM(5));  

L_LT_DONE:
  POP(R4);
  POP(R3);
  POP(R2);
  POP(R1);
  POP(FP);
  RETURN;

L_LT_F:

MOV(R0, IMM(3));  
JUMP(L_LT_DONE);
